<template>
    <van-row>
        <div :id="chartdomid" style="width:100%;height:350px;padding 10px 0px"></div>
    </van-row>
</template>

<script>
const echarts = require('echarts')
export default {
  name: 'DeptRecitfyIntimeAnalysis',
  props: ['chartdomid', 'intimeDetail'],
  data () {
    return {
      echarts: null,
      options: null
    }
  },
  mounted () {
    this.echarts = echarts.init(document.getElementById(this.chartdomid))
    this.options = {
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        }
      },
      legend: {
        data: ['完成率', '及时率']
      },
      grid: {
        containLabel: true
      },
      xAxis: {
        type: 'value',
        show: true
      },
      yAxis: {
        type: 'category',
        data: []
      },
      series: [
        {
          name: '完成率',
          type: 'bar',
          label: {
            show: true
          },
          data: []
        },
        {
          name: '及时率',
          type: 'bar',
          label: {
            show: true
          },
          data: []
        }
      ]
    }
  },
  methods: {
    renderData () {
      console.log(this.intimeDetail)
      this.options.yAxis.data = []
      this.options.series[0].data = []
      this.options.series[1].data = []
      if (this.intimeDetail.length > 0) {
        for (let i = 0; i < this.intimeDetail.length; i++) {
          this.options.yAxis.data[i] = this.intimeDetail[i].bmmc
          let wancheng = 0
          if (this.intimeDetail[i].problem_count > 0) {
            wancheng = (this.intimeDetail[i].complete_count / this.intimeDetail[i].problem_count * 100).toFixed(2)
          }
          this.options.series[0].data[i] = wancheng
          let jishi = 0
          let tmp = this.intimeDetail[i].intime_complete + this.intimeDetail[i].timeout_complete + this.intimeDetail[i].timeout_uncomplete
          if (tmp > 0) {
            jishi = (this.intimeDetail[i].intime_complete / tmp * 100).toFixed(2)
            console.log(jishi)
          }

          this.options.series[1].data[i] = jishi
        }
        console.log(this.options)
        this.echarts.setOption(this.options)
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>
